<?php
/**
 * 网站首页控制层
 * 
 * @copyright 	Copyright (c) 2011 thinkapk.com All rights reserved.
 * @package 	ThinkAPK_Action
 * @link 		http://www.thinkapk.com/
 * @author 		richie <richbossman@163.com>
 * @version 	$Id: IndexAction.class.php 7482 2011-05-19 10:12:51Z richie $
 * 
 */
class IndexAction extends ThinkAPK_Action_Web 
{
    //首页
    public function _before_index(){
    	$this->setTitle(C('shop_index_title'));
    	$topRecommend = D('Goods')->getIndexTopRcommend();
    	$mainPlay = $this->indexMainPlay();
    	//主播放图片
    	$this->assign('mainplay', $mainPlay);
    	//顶部推荐
    	$this->assign('toprecommend', $topRecommend);
    	//下载排行
    	$this->assign('tops', $this->indexTops());
    	//新应用
    	$this->assign('news', $this->newApp());
    	unset($topRecommend, $mainPlay);
    	//正在下载...
    	$this->assign('downloading', D('Goods')->downloading(5));
    	//推荐分类
    	$this->assign('recommend_app', D('Category')->getIndexRecommendCat(C('APP_ID')));
		$this->assign('recommend_game', D('Category')->getIndexRecommendCat(C('GAME_ID')));
		//推荐应用与游戏
		$this->assign('recommend_app_list', D('Goods')->recommendApp(C('APP_ID')));
		$this->assign('recommend_game_list', D('Goods')->recommendApp(C('GAME_ID')));
		//友情链接
		$this->assign('friendlink', D('FriendLink')->get());
		//SEO
    	$this->setKeywords(C('shop_keywords'));
    	$this->setDescription(C('shop_desc'));
    }
    
    //下载排行
    public function indexTops(){
    	$tops = array(
    		'all' => D('GoodsCount')->get(0, 6),
    		'app' => D('GoodsCount')->get(C('APP_ID'), 6),
    		'game' => D('GoodsCount')->get(C('GAME_ID'), 6)
    	);
    	return $tops;
    }
    
    //新应用
    public function newApp(){
    	return array(
    		'all' => D('Goods')->newApp(),
    		'app' => D('Goods')->newApp(C('APP_ID')),
    		'game' => D('Goods')->newApp(C('GAME_ID'))
    	);
    }
	
	function clearcaches(){
		$this->clearCache();
	}
	
	/**
	 * 首页大图广告
	 *
	 * @return array
	 */
	private function indexMainPlay(){
		$row = M('RelationPic')->where(array('type'=>'main_flash', 'pid'=>0))->field('link,title,pic,id')->order('sort_order ASC, id DESC')->findAll();
		return $row;
	}
	
	function test(){
		$row = M('Temp')->where('is_down=0')->field('id,file_url')->findAll();
		foreach ($row as $res){
			M('Temp')->where('id='.$res['id'])->save(array('is_ok'=>1));
			echo $res['file_url'].'<br />';
		}
	}
}
?>